// import { SceneObjectPickedInfo } from 'xbsj-xe2/dist-node/xe2-base-objects';
// import { createNextAnimateFrameEvent } from 'xbsj-xe2/dist-node/xe2-base-utils';
// import { UeViewer, calcFlyToParamCallFunc, destroyCallFunc, flyToCallFunc, UeObject, flyInCallFunc } from "xbsj-xe2/dist-node/xe2-ue-objects";
// import { ESVisualObject } from '../../objs';
// import { UeESSceneObject } from '../UeESSceneObject';

import { ESVisualObject, SceneObjectPickedInfo } from "earthsdk2s";
import { UeESSceneObject } from "../UeESSceneObject";
import { ESUeViewer } from "@/ESUeViewer";
import { calcFlyToParamCallFunc, flyInCallFunc, flyToCallFunc } from "@/ESUeViewer/uemsg/CallUeFuncs";


export class UeESVisualObject<T extends ESVisualObject = ESVisualObject> extends UeESSceneObject<T> {
    constructor(sceneObject: T, ueViewer: ESUeViewer) {
        super(sceneObject, ueViewer);
        const viewer = ueViewer.viewer;
        if (!viewer) {
            console.warn(`viewer is undefined!`);
            return;
        }

        this.d(sceneObject.flyToEvent.don((duration) => {
            flyToCallFunc(viewer, sceneObject.id, duration)
        }));
        this.d(sceneObject.flyInEvent.don((duration) => {
            flyInCallFunc(viewer, sceneObject.id, sceneObject.flyInParam?.position, sceneObject.flyInParam?.rotation, (duration ?? 1))
        }));

        this.d(sceneObject.calcFlyToParamEvent.don(() => {
            calcFlyToParamCallFunc(viewer, sceneObject.id)
        }));
        this.d(sceneObject.calcFlyInParamEvent.don(() => {
            if (!ueViewer.actived) return;
            const cameraInfo = ueViewer.getCurrentCameraInfo();
            if (!cameraInfo) return;
            const { position, rotation } = cameraInfo;
            sceneObject.flyInParam = { position, rotation, flyDuration: 1 };
        }));

        this.d(ueViewer.propChanged.don((info) => {
            if (info.objId !== sceneObject.id) return
            Object.keys(info.props).forEach(key => {
                const prop = info.props[key] === null ? undefined : info.props[key]
                // @ts-ignore
                sceneObject[key] = prop
            });
        }));

        //todo ysp
        // this.d(ueViewer.uePickedEvent.don((uePickInfo) => {
        //     if (!uePickInfo) return;
        //     const { uePickResult } = uePickInfo;
        //     if (!(uePickResult && uePickResult.id)) return;
        //     if (uePickResult.id === sceneObject.id) {
        //         if (sceneObject.allowPicking ?? ESVisualObject.defaults.allowPicking) {
        //             sceneObject.pickedEvent.emit(new SceneObjectPickedInfo(sceneObject, uePickInfo));
        //         } else {
        //             ueViewer.sceneObjetNotAllowPickEvent.emit();
        //         }
        //     }
        // }));

    }
}
